package org.example.demos.pattern.chain_pattern;

import java.util.*;

public class Test {


    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        List<CheckChainContext> list = buildChain();
        Map<String,Object> voucher = new HashMap<String, Object>();
        Iterator<CheckChainContext> it = list.iterator();
        if (it.hasNext()) {
            CheckChainContext next = it.next();
            AbstractCheckHandler handler = (AbstractCheckHandler)next.getCheckClass().newInstance();
            handler.checkField(voucher,next,it);
        }


    }

    private static List<CheckChainContext> buildChain(){
        List<CheckChainContext> list = new ArrayList<CheckChainContext>();
        Map<String,Class> map1 = new HashMap<String, Class>();
        CheckChainContext c1 = new CheckChainContext("org",OrgCheckHandler.class);
        list.add(c1);
        CheckChainContext c2 = new CheckChainContext("agent",AgentCheckHandler.class);
        list.add(c2);
        return list;
    }
}
